<?php
 Session_Start () ;
 If (!$_SESSION ["repertoire_config"]) { Header ("Location: ../../") ; }
 Include ("../../include/garennes.cfg") ;
 Include ("../../include/init.php") ;
 Include ("../include/config.inc") ;
 verif_droits ($droit_courant, $_SESSION ["code"]) ;
 
 Include ("../../include/var_temp.inc") ;
 
 If (IsSet ($requete))
  {
   If ($requete == "Ajouter")
    {
     // Ajout d'une salle de classe
     If (!Is_Numeric ($capacite)) { $capacite = 1 ; }
     $ok = SQL_commande ("INSERT INTO abs_salles (id_abs_salle,nom,capacite)
                          VALUES ('','".Str_Replace ("'", "`", $nom)."','".$capacite."')", $id_sql) ;
     $message = 1 ;
    }
   ElseIf ($requete == "Effacer")
    {
     // Requete possible si aucun lien avec l'EDT et le report EDT
     // Effacement d'une salle de classe
     $ok = SQL_commande ("DELETE FROM abs_salles WHERE id_abs_salle='".$id_abs_salle."' LIMIT 1", $id_sql) ;
     // Mise a zero de la salle dans l'EDT
     $ok = SQL_commande ("UPDATE abs_edt SET abs_salle='0' WHERE abs_salle='".$id_abs_salle."'", $id_sql) ;
     // Mise a zero de la salle dans le report EDT
     $ok = SQL_commande ("UPDATE abs_reports_edt SET abs_salle='0' WHERE abs_salle='".$id_abs_salle."'", $id_sql) ;
     $ok = SQL_commande ("UPDATE abs_reports_edt SET salle_report='0' WHERE salle_report='".$id_abs_salle."'", $id_sql) ;
     $message = 2 ;
    }
  }

 $resultats = SQL_commande ("SELECT * FROM menus WHERE numero='".$droit_courant."' AND ordre='0'", $id_sql) ;
 $l = SQL_tableau_associatif ($resultats, "") ; 

 If ($id_classe > 0)
  {
   $resultat = SQL_commande ("SELECT nom,nom_bref FROM classes WHERE id_classe='".$id_classe."' LIMIT 1", $id_sql) ;
   $classe = SQL_tableau_associatif ($resultat, "") ;
  }

 Echo "<HTML>\n" ;
 Echo " <HEAD>\n" ;
 entete_html ("Garennes", "travail_affichage", 1) ;
 Echo styles ("none", "none", "none", $l ["lien"], "none") ;
 //Include ("./abs_gestion_salles.js") ;
 Echo " </HEAD>\n" ;
 
 Echo " <BODY BACKGROUND=\"../images/fond.png\" TEXT=\"#000000\">\n" ;
 //Echo "  <SCRIPT> top.travail.travail_menu.document.gestion_salles.id_classe.value=0 </SCRIPT>\n" ;
 Echo "  <TABLE WIDTH=\"100%\" BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\">\n" ;
 Echo "   <TR>\n" ;
 Echo "    <TD></TD>\n" ;
 Echo "    <TD WIDTH=\"100%\" ALIGN=\"CENTER\">Gestion&nbsp;des&nbsp;salles&nbsp;</TD>\n" ;
 Echo "    <TD><A HREF=\"javascript:ouvrefenetre('./aide.php?aide=5&rep=".$_SESSION ["repertoire_config"]."',350,650);\" OLDREF><IMG SRC=\"../images/aide.png\" BORDER=\"0\"></A></TD>\n" ;
 Echo "   </TR>\n" ;
 Echo "  <TABLE>\n" ;
 
 If ($message)
  {
   Echo "  <CENTER><FONT COLOR=\"#FF0000\"><B><BLINK>" ;
   Switch ($message)
    {
     Case 1 : Echo "Ajout&nbsp;effectu&eacute;&nbsp;!" ;
              Break ;
     Case 2 : Echo "Suppression&nbsp;effectu&eacute;e&nbsp;!" ;
              Break ;
    }
   Echo "</BLINK></B></FONT></CENTER>\n" ;
  }

 // Ajouter une salle
 Echo "  <TABLE BORDER=\"1\" BGCOLOR=\"".$l ["couleur_fond"]."\" CELLSPACING=\"0\" CELLPADDING=\"0\" ALIGN=\"CENTER\">\n" ;
 Echo "   <TR>\n" ;
 Echo "    <TD>\n" ;
 Echo "     <TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\">\n" ;
 Echo "      <FORM ACTION=\"".$_SERVER ["PHP_SELF"]."\" METHOD=\"POST\" NAME=\"ajout\" OnSubmit=\"javascript:return verif_ajout()\">\n" ;
 //Echo "       <INPUT TYPE=\"HIDDEN\" NAME=\"id_classe\" VALUE=\"".$id_classe."\">\n" ;
 //Echo "       <INPUT TYPE=\"HIDDEN\" NAME=\"code_classe\" VALUE=\"".$classe ["nom_bref"]."\">\n" ;
 Echo "       <INPUT TYPE=\"HIDDEN\" NAME=\"requete\" VALUE=\"Ajouter\">\n" ;
 Echo "       <TR><TD ALIGN=CENTER COLSPAN=3>&nbsp;<B>Ajouter&nbsp;une&nbsp;nouvelle&nbsp;salle</B>&nbsp;<BR>&nbsp;</TD></TR>\n" ;
 Echo "       <TR>\n" ;
 Echo "        <TD ALIGN=RIGHT><FONT SIZE=\"".$l ["titre"]."\">&nbsp;<B>Nom&nbsp;de&nbsp;la&nbsp;salle</B>&nbsp;:&nbsp;</FONT></TD>\n" ;
 Echo "        <TD COLSPAN=\"2\"><FONT SIZE=\"".$l ["titre"]."\"><INPUT TYPE=\"TEXT\" NAME=\"nom\" SIZE=\"10\" MAXLENGTH=\"20\"></FONT>&nbsp;</TD>\n" ;
 Echo "       </TR>\n" ;
 Echo "       <TR>\n" ;
 Echo "        <TD ALIGN=RIGHT><FONT SIZE=\"".$l ["titre"]."\">&nbsp;<B>Capacit&eacute;&nbsp;de&nbsp;la&nbsp;salle</B>&nbsp;:&nbsp;</FONT></TD>\n" ;
 Echo "        <TD COLSPAN=\"2\"><FONT SIZE=\"".$l ["titre"]."\"><INPUT TYPE=\"TEXT\" NAME=\"capacite\" SIZE=\"3\" MAXLENGTH=\"5\" VALUE=\"1\"></FONT>&nbsp;</TD>\n" ;
 Echo "       </TR>\n" ;
 Echo "       <TR>\n" ;
 Echo "        <TD ALIGN=\"RIGHT\" COLSPAN=\"3\">\n" ;
 Echo "         <INPUT TYPE=\"HIDDEN\" NAME=\"code\" VALUE=\"".$_SESSION ["code"]."\">\n" ;
 Echo "         <INPUT TYPE=\"HIDDEN\" NAME=\"id_abs_validite\" VALUE=\"".$id_abs_validite."\">\n" ;
 Echo "         <INPUT TYPE=\"IMAGE\" SRC=\"../images/absences/valider.png\" VALUE=\"Valider\" BORDER=\"0\">\n" ;
 Echo "        </TD>\n" ;
 Echo "       </TR>\n" ;
 //Echo "       <TR><TD COLSPAN=\"3\">&nbsp;</TD></TR>\n" ;
 Echo "      </FORM>\n" ;
 Echo "     </TABLE>\n" ;
 Echo "    </TD>\n" ;
 Echo "   </TR>\n" ;
 Echo "  </TABLE>\n" ;
 
 // Bouton annuler
 Echo "  <BR>\n" ;
 Echo "  <FORM ACTION=\"./abs_initialisations.php\" NAME=\"annuler\" METHOD=\"POST\">\n" ;
 Echo "   <CENTER>\n" ;
 Echo "    <INPUT TYPE=\"HIDDEN\" NAME=\"code\" VALUE=\"".$_SESSION ["code"]."\">\n" ;
 Echo "    <INPUT TYPE=\"HIDDEN\" NAME=\"menu\" VALUE=\"2\">\n" ;
 Echo "    <INPUT TYPE=\"IMAGE\" SRC=\"../images/absences/annuler.png\" BORDER=0>\n" ;
 Echo "   </CENTER>\n" ;
 Echo "  </FORM>\n" ;

 Echo "  <BR>\n" ;
 
 // Ensemble des salles existantes
 $resultats = SQL_commande ("SELECT * FROM abs_salles ORDER BY nom,capacite", $id_sql) ;
 If (SQL_nbr_lignes ($resultats) > 0)
  {
   Echo "  <TABLE BORDER=1 BGCOLOR=\"".$l ["couleur_fond"]."\" CELLSPACING=0 CELLPADDING=0 ALIGN=CENTER>\n" ;
   Echo "   <TR>\n" ;
   Echo "    <TD>\n" ;
   Echo "     <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>\n" ;
   Echo "      <TR><TD ALIGN=CENTER COLSPAN=2>&nbsp;<B>Salle" ; If (SQL_nbr_lignes ($resultats) > 1) { Echo "s" ; }
   Echo "&nbsp;actuelle" ; If (SQL_nbr_lignes ($resultats) > 1) { Echo "s" ; }
   Echo "</B>&nbsp;<BR>&nbsp;</TD></TR>\n" ;
   For ($i = 0 ; $i < SQL_nbr_lignes ($resultats) ; $i++)
    {
     $r = SQL_tableau_associatif ($resultats, "") ;
     Echo "      <TR>\n" ;
     Echo "       <TD ALIGN=RIGHT>&nbsp;<B>".$r ["nom"]."</B>&nbsp;(".$r ["capacite"].")&nbsp;</TD>\n" ;
     Echo "       <FORM ACTION=\"".$_SERVER ["PHP_SELF"]."\" NAME=\"efface\" METHOD=\"POST\" OnSubmit=\"return valide ('".Str_Replace ("'", "\\'", $r ["code_groupe"])."')\">\n" ;
     Echo "        <TD ALIGN=\"RIGHT\">\n" ;
     Echo "         <INPUT TYPE=\"HIDDEN\" NAME=\"id_abs_salle\" VALUE=\"".$r ["id_abs_salle"]."\">\n" ;
     Echo "         <INPUT TYPE=\"HIDDEN\" NAME=\"requete\" VALUE=\"Effacer\">\n" ;
     Echo "         &nbsp;<INPUT TYPE=\"IMAGE\" SRC=\"../images/absences/supprimer.png\" BORDER=\"0\">&nbsp;\n" ;
     Echo "        </TD>\n" ;
     Echo "       </FORM>\n" ;
     Echo "      </TR>\n" ;
    }
   Echo "      <TR><TD ALIGN=CENTER COLSPAN=2>&nbsp;</TD></TR>\n" ;
   Echo "     </TABLE>\n" ;
   Echo "    </TD>\n" ;
   Echo "   </TR>\n" ;
   Echo "  </TABLE>\n" ;
  }
 Else
  {
   Echo "<CENTER>&nbsp;Aucune&nbsp;salle&nbsp;dans&nbsp;la&nbsp;base</CENTER>\n" ;
  }
 
 Echo " </BODY>\n" ;
 Echo "</HTML>\n" ;
?>